package com.ryan.security.config;

import com.ryan.security.core.properties.SecurityProperties;
import com.ryan.security.filters.TimeFilter;
import com.ryan.security.interceptors.Timeinterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by kaimin on 1/1/2019.
 * time : 10:45
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{


    @Autowired
    private Timeinterceptor timeinterceptor;



    //这里就是配异步处理的一些支持
    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
//        configurer.registerCallableInterceptors();
//        configurer.registerDeferredResultInterceptors();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(timeinterceptor);
    }
//    @Bean
    public FilterRegistrationBean timeFilter(){
        FilterRegistrationBean registrationBean=new FilterRegistrationBean();
        TimeFilter timeFilter=new TimeFilter();
        registrationBean.setFilter(timeFilter);
        //可以指定哪些url起作用
        List<String> urls = new ArrayList<>();
        urls.add("/*");
        registrationBean.setUrlPatterns(urls);

        return registrationBean;
    }


}
